package com.symaster.common.connect.local;

import com.symaster.common.connect.tcp.TcpElementR;
import com.symaster.common.connect.tcp.TcpElementW;
import com.symaster.common.util.IOUtil;

import java.io.Closeable;
import java.io.IOException;
import java.util.UUID;

/**
 * @author yinmiao
 * @version 2022-05-03 19:07
 */
public class ConnectObj implements Closeable {

    private final String uuid;
    private String ip;
    private int port;
    private TcpElementR tcpElementR;
    private TcpElementW tcpElementW;

    public ConnectObj(String uuid) {
        this.uuid = uuid;
    }

    public ConnectObj() {
        uuid = UUID.randomUUID().toString();
    }

    public String getUuid() {
        return uuid;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public TcpElementR getTcpElementR() {
        return tcpElementR;
    }

    public void setTcpElementR(TcpElementR tcpElementR) {
        this.tcpElementR = tcpElementR;
    }

    public TcpElementW getTcpElementW() {
        return tcpElementW;
    }

    public void setTcpElementW(TcpElementW tcpElementW) {
        this.tcpElementW = tcpElementW;
    }

    @Override
    public void close() throws IOException {
        IOUtil.close(tcpElementR, tcpElementW);
    }

    @Override
    public String toString() {
        return "ConnectObj{" +
                "uuid='" + uuid + '\'' +
                ", ip='" + ip + '\'' +
                ", port=" + port +
                ", tcpElementR=" + tcpElementR +
                ", tcpElementW=" + tcpElementW +
                '}';
    }
}
